<template>
	<view class="content1">
		<navbar @goBack="goBack"></navbar>
		<view class="products-swiper">
			<swiper class="swiper" :autoplay="autoplay" @change="onSwipeChange">
				<swiper-item v-for="(item, index) in detail.banner" :key="index">
					<view class="swiper-item">
						<image class="img" :src="item" mode="widthFix" />
					</view>
				</swiper-item>
			</swiper>
			<!-- custom swiper dots -->
		<!-- 	<view class="swiper-bottom">
				<view class="name">{{ name }}</view>
			</view> -->
		</view>
		<view class="content_c">
			<view class="content1">
				<text class="ponit"><text class="num">2355</text>积分</text>
				<text class="stock">剩余：2025</text>
			</view>
			<text class="name">xinshijieee</text>
		</view>
		<view class="goods" v-if="type=='2'">
			<view class="fahuobg">
				请选择可用于兑换的赏品
			</view>
			<view class="goodslist">
				<view v-for="(item,index) in goods" :key="index" class="item">
					<view class="goodsimg">
						<image class="img" :src="item.image">
						</image>
					</view>
					<view class="opbtn">
						<button class="btnreduce " :class="[item.num==0?'disable':'']" @click="reduce(index)">-</button>
						<view class="num">{{ item.num }}</view>
						<button class="btnadd" :class="[item.num==item.count?'disable':'']" @click="add(index)">+</button>
					</view>
				</view>
			</view>
			<view class="btn1">
				<image class="duihuanbtn2" src="/static/owo/duihuanbtn.png"></image>
			</view>
		</view>
		<view class="btn" v-else>
			<image class="duihuanbtn2" src="/static/owo/duihuanbtn2.png"></image>
		</view>
	</view>
</template>

<script setup lang="ts">
	import navbar from '@/wxcomponents/navbar'
	import {
		listPackage,
	} from "@/api/package";
	import {
		onLoad,
		onReachBottom,
		onPullDownRefresh,
		onShow
	} from "@dcloudio/uni-app"
	import {
		ref,
		reactive,
		defineProps,
		onUnmounted,
		computed
	} from 'vue'
	import {
		listYiFanShang
	} from '@/api/yifanshang';
	let type = ref("1")
	let goods = ref([]);
	let autoplay = ref(true);
	let detail = ref({
		banner: [
			"https://api-common.wzkj-dev.com/cdn-nativa/VSrBWlMv5QK0_822016737.jpg",
			"https://api-common.wzkj-dev.com/cdn-nativa/VSrBWlMv5QK0_822016737.jpg"
		]
	})
	function reduce(index) {
		if(goods.value[index].num>0) {
			--goods.value[index].num
		}
	}
	function add(index) {
		if(goods.value[index].num<goods.value[index].count) {
			++goods.value[index].num
		}
	}
	function goBack() {
		uni.navigateBack(-1)
	}
	onLoad((option) => {
		getlistPackage()
		type.value = option.type
	})
	async function getlistPackage() {
		const res = await listPackage();
		const data = res.data || {};
		const items = data.items || [];
		for (let i = 0; i < items.length; i++) {
			items[i]["num"] = items[i]["count"];
		}
		goods.value = items;
	}
	// tab切换
	async function onSwipeChange(event) {
		// activeTab.value = event.detail.current

		// activeTab.value = tabName
		// if (tabName === "all") {
		// } else {

		// }
		// getlistYiFanShang();
	}
</script>

<style lang="scss">
	@import 'src/static/scss/common';

	.goods {
		width: 100%;
		background-color: #18181C;
		padding: 30rpx;
		margin-top: 24rpx;
		box-sizing: border-box;

		.fahuobg {
			box-sizing: border-box;
			width: 702rpx;
			height: 40rpx;
			line-height: 40rpx;
			margin: 20rpx auto;
			background-image: url("/static/owo/tipbg.png");
			background-position: 0 0;
			background-repeat: no-repeat;
			background-size: 100%;
			color: #FFFFFF;
			font-size: 20rpx;
			text-align: center;
		}
		.goodslist {
			width: 100%;
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			gap: 12rpx;
			justify-content: flex-start;
			margin:24rpx 0;
			.item {
				// width: 2%;
				margin-right: 1%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				.goodsimg {
					width: 156rpx;
					height: 156rpx;
					background: url("/static/owo/smallbg.png");
					background-repeat: no-repeat;
					background-position: 0;
					background-size: 100%;
					margin-bottom: 10rpx;
					display: flex;
					flex-direction: row;
					justify-content: center;
					align-items: center;
					.img {
						width: 98%;
						height: 98%;
					}
				}
				 .opbtn {
					 width: 156rpx;
				 	color: #ffffff;
				 	display: flex;
				 	justify-content: space-between;
				 	.num {
						background-color: #33331D;
				 		width: 60rpx;
				 		height: 28rpx;
				 		text-align: center;
				 		line-height: 28rpx;
						color: #FFFFFF;
				 	}
					.btnadd,.btnreduce {
						color: #7A5E15;
						width: 28rpx;
						height: 28rpx;
						text-align: center;
						line-height: 28rpx;
						background-color: #FFDD86;
					}
					.btnadd.disable,.btnreduce.disable {
						opacity: 0.45;
					}
				 }
			}
			.item:nth-child(4n+4) {
				margin-right: 0%;
			}
		}
	}
	button::after {
		padding: 0;
		margin: 0;
		border-radius: 0;
		line-height: 28rpx;
	}
	button {
		border-radius: 0;
		padding: 0;
		margin: 0;
	}
	.content_c {
		width: 100%;
		background-color: #18181C;
		padding: 30rpx;
		box-sizing: border-box;

		.content1 {
			display: flex;
			justify-content: space-between;
			flex-direction: row;
			align-items: center;
			margin-bottom: 10rpx;

			.ponit {
				font-size: 24rpx;
				color: rgba(255, 255, 255, 0.65);

				.num {
					color: #FFDD86;
					font-size: 36rpx;
					padding-right: 6rpx;
				}
			}

			.stock {
				color: rgba(255, 255, 255, 0.65);
				font-size: 24rpx;
			}
		}

		.name {
			color: #FFFFFF;
			font-size: 32rpx;
		}
	}

	.btn1 {
		width: 100%;
		text-align: center;
		z-index: 999;

		.duihuanbtn2 {
			width: 686rpx;
			height: 84rpx;
		}
	}

	.btn {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 60rpx;
		text-align: center;
		z-index: 999;

		.duihuanbtn2 {
			width: 686rpx;
			height: 84rpx;
		}
	}

	.products-swiper {
		width: 100%;
		min-height: 606rpx;

		.swiper {
			min-height: 606rpx;

			.swiper-item {
				width: 100%;
				height: 100%;

				.img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	page {
		background-color: rgba(44, 44, 55, 1);
	}

</style>